<?php
namespace App\Models;
use Illuminate\Support\Facades\DB;

class LogGoodsView extends CommonModel {
	protected $table = 'log_goods_view';

    /**
     * 增加访客记录，商品查看记录，
     * @param $goods_id int 商品ID
     * @param $goods_type int 商品类型
     * @param $uid int 用户ID
     * @param $store_id int 店铺ID
     */
    public function addGoodsView($goods_id, $goods_type,$uid,$store_id){
        $array = [
            'goods_id'=>$goods_id,
            'goods_type'=>$goods_type,
            'uid'=>$uid,
            'store_id'=>$store_id,
            'ip'=>request()->ip(),
            'date'=>date('Y-m-d')
        ];
        $check = self::where($array)->first();
        if(!$check) {
            ShopGoodsStock::addGoodsView($goods_id, $goods_type);
            self::create($array);
            return true;
        }else{
            return true;
        }
    }
}